<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="/template.xhtml">
    
        <ui:define name="title">
            <h:outputText value="#{bundle.ListExpensesTitle}"></h:outputText>
        </ui:define>

        <ui:define name="body">
            <h:outputScript name="js/jsfunctions.js" />
            <h:form styleClass="jsfcrud_list_form" id="form">
                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="#{bundle.ListExpensesEmpty}" rendered="#{expensesController.items.rowCount == 0}"/>
                <h:panelGroup rendered="#{expensesController.items.rowCount > 0}">
                    <h:outputText value="#{expensesController.pagination.pageFirstItem + 1}..#{expensesController.pagination.pageLastItem + 1}/#{expensesController.pagination.itemsCount}"/>&nbsp;
                    <h:commandLink action="#{expensesController.previous}" value="#{bundle.Previous} #{expensesController.pagination.pageSize}" rendered="#{expensesController.pagination.hasPreviousPage}"/>&nbsp;
                    <h:commandLink action="#{expensesController.next}" value="#{bundle.Next} #{expensesController.pagination.pageSize}" rendered="#{expensesController.pagination.hasNextPage}"/>&nbsp;
                    
                    <h:dataTable id="mytable" value="#{expensesController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">

                        <h:column>
                            <f:facet name="header">
                                <h:selectBooleanCheckbox onchange='SelectAllCheckboxesSpecific(this)'/>
                            </f:facet>
                            <h:selectBooleanCheckbox  value="#{expensesController.checked[item.expId]}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseDate}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseDate}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_project}"/>
                            </f:facet>
                            <h:outputText value="#{item.project.projectName}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_task}"/>
                            </f:facet>
                            <h:outputText value="#{item.task}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseType}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseType}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_comment}"/>
                            </f:facet>
                            <h:outputText value="#{item.comment}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_reimbursable}"/>
                            </f:facet>
                            <h:outputText value="#{item.reimbursable}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_units}"/>
                            </f:facet>
                            <h:outputText value="#{item.units}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_currency}"/>
                            </f:facet>
                            <h:outputText value="#{item.currency.currencyCode}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseAmount}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseAmount}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_employee}"/>
                            </f:facet>
                            <h:outputText value="#{item.employee.businessEmail}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_createdAt}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_createdBy}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdBy.businessEmail}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_expenseTotal}"/>
                            </f:facet>
                            <h:outputText value="#{item.expenseTotal}"/>
                        </h:column>
                        
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListExpensesTitle_status}"/>
                            </f:facet>
                            <h:outputText value="#{item.status}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <h:commandLink action="#{expensesController.prepareView}" value="#{bundle.ListExpensesViewLink}"/>
                            <h:outputText value=" "/>
                            <h:commandLink rendered="#{item.status != 'submitted'}" action="#{expensesController.prepareEdit}" value="#{bundle.ListExpensesEditLink}"/>
                        </h:column>
  
                    </h:dataTable>
                </h:panelGroup>
                <br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <h:commandButton value="#{bundle.ListExpensesCreateLink}" type="submit" action="#{expensesController.prepareCreate}"/>
                <h:commandButton value="Delete" action="#{expensesController.deleteSelected}" />
                <h:commandButton value="Submit" action="#{expensesController.submitSelected}" />
                <h:button value="Get Expenses" outcome="expensesresult" />
                <h:button rendered="${type=='admin'}" value="Back to Home" outcome="/index" />
                <h:button rendered="${type=='user'}" value="Back to Home" outcome="/userhome"/>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
